package com.zyg.manager.config;

import brave.sampler.Sampler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.sleuth.sampler.ProbabilityBasedSampler;
import org.springframework.cloud.sleuth.sampler.SamplerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SleuthSamplerConfiguration {

  @Value("${sleuth.sampler.probability}")
  private String probability;

  @Bean
  public Sampler defaultSampler() throws Exception {
    Float f = new Float(probability);
    SamplerProperties samplerProperties = new SamplerProperties();
    samplerProperties.setProbability(f);
    ProbabilityBasedSampler sampler = new ProbabilityBasedSampler(samplerProperties);
    return sampler;
  }
}